1. Field of the Invention
The present invention relates to image processing, and more specifically, to a method determining if an image is a color image, a black and white image, or a gray image.
2. Description of the Prior Art
When acquiring digital images such as by using a scanner or a digital still camera, it is important to know what type of image has been acquired. Image types can be classified according to the color composition of the image. For example, three main types of images are color images, black and white images, and gray images. Since the color composition of an image should be determined before image processing is performed, it is important to quickly and efficiently determine the color composition of images.
Please refer to FIG. 1. FIG. 1 is a flowchart illustrating a method for determining color composition of an image according to the prior art. The method starts with step 10. In step 12, intensity and saturation values are calculated for each pixel in the image. The intensity and saturation values are used to determine if the corresponding pixels are color pixels or not. The prior art method utilizes a lookup table stored in memory to store intensity values, corresponding saturation values, and information stating whether the pixel is a color pixel or not. In step 14, the intensity and saturation values for each pixel in the image are compared with data stored in the lookup table, and each pixel in the image is categorized as being a color pixel or not a color pixel.
In step 16, color density analysis is performed on masks of nearby pixels. Please refer to FIG. 2. FIG. 2 illustrates using a mask 44 to perform color density detection. Array 40 contains binary information indicating whether each pixel 42 in the image is a color pixel or not. For example, in FIG. 2 the binary value of “1” indicates that the corresponding pixel 42 is a color pixel. The mask 44 can be of any size, but is shown in FIG. 2 as a 3×3 mask, meaning that the mask 44 has dimensions of three pixels by three pixels. The mask 44 is applied to various different groups of pixels in the array 40 to determine the density of color pixels in the mask 44. Each time the mask 44 is applied, the number of pixels 42 contained by the mask 44 is counted. In step 18, this color pixel count is compared to a predetermined density value. If the color pixel count exceeds the predetermined density value, the image is labeled as a color image in step 20, thereby ending the process of determining the color composition of the image. On the other hand, if the color pixel count does not exceed the predetermined density value for any group of nearby pixels in the image, the method proceeds to step 22.
After deciding that the image is not a color image, the prior art method then determines whether the image is a black and white image or a gray image. To accomplish this, a histogram is calculated using the intensity values of all pixels of the image in step 22. Please refer to FIG. 3. FIG. 3 is a histogram 50 showing the number of pixels of the image having a particular intensity level. As an example, assume that the intensity levels of each of the pixels can range from 0 to 1, inclusively. These intensity levels can be divided into a smaller number of discrete levels. As shown in FIG. 3, the histogram 50 is divided into 15 intensity levels, labeled L1-L15. The histogram 50 contains vertical bars corresponding to the intensity levels L1-L15, and the height of the bars represent the number of pixels having intensity values within the various intensity levels. After the histogram 50 is calculated, the histogram 50 is analyzed for patterns that indicate either a black and white image or a gray image.
In step 24, the prior art method determines whether the histogram 50 indicates that a large percentage of pixels are concentrated in one of the intensity levels. If, for instance more than 80% of the pixels all fall into the same intensity level, the image is labeled as a black and white image in step 30, thereby ending the process of determining the color composition of the image. If this is not the case, the histogram 50 is analyzed in step 26 to see if the pixels are substantially arranged in two opposing extremes. If so, the two extremes represent black pixels and white pixels, and the image is labeled as a black and white image in step 30.
If neither of the conditions in steps 24 and 26 are satisfied, the histogram 50 is analyzed in step 28 to determine if the intensity of the pixels indicate that there is a large percentage of gray pixels. If the number of gray pixels is greater than a predetermined value, the image is labeled as a gray image in step 32 and the process is ended. Conversely, if the number of gray pixels is not greater than the predetermined value, the image is labeled as a black and white image in step 30 and the process is ended.
Although the prior art method is able to determine whether an image is color, black and white, or gray, the use of a lookup table in step 14 for comparing with the intensity and saturation values of each pixel in the image consumes many resources. First of all, memory is required for storing the lookup table. The lookup table could consume a considerable amount of memory depending on the amount of data used in the lookup table. Second, the prior art method searches the lookup table to compare the intensity and saturation values of each pixel with the values stored in the lookup table. Repeatedly searching and comparing for all of the pixels in the image requires a large amount of both processing power and time. For these reasons, a simplified method of determining the color composition of an image is needed.